package com.beta.restapi.controller;

import com.beta.common.web.ContentType;
import com.beta.em.ConfirmCodeType;
import com.beta.restapi.internal.Consts;
import com.beta.restapi.internal.annotation.AuthSetting;
import com.beta.restapi.internal.annotation.AuthStrategy;
import com.beta.service.IConfirmationCodesService;
import com.beta.restapi.request.ConfirmationCodeRequest;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by vector on 2016/11/21.
 */
@Api(tags = {"ConfirmationCode"})
@RestController
@RequestMapping(Consts.API_PATH_PREFIX + Consts.Resource.CONFIRMATION_CODE)
public class ConfirmationCodeController extends BaseController {

    @Autowired
    private IConfirmationCodesService confirmationCodesService;

    @AuthSetting(level = AuthStrategy.ANONYMOUS)
    @PostMapping(value = "", produces = {ContentType.JSON})
    public Object create(@RequestBody ConfirmationCodeRequest request) {
        ConfirmationCodeRequest.ConfirmationCode confirmationCode = request.getConfirmationCode();
        confirmationCodesService.createCode(confirmationCode.getPhone(),
                ConfirmCodeType.getType(confirmationCode.getCodeType()));
        return ok();
    }

}
